This application claims priorities of Korean Patent Application Nos. 10-2003-0021502 and 10-2003-0063342 filed on Apr. 4, 2003, and Sep. 9, 2003, respectively in the Korean Intellectual Property Office, the contents of which are incorporated herein by reference.
1. Field of the Invention
Apparatuses and methods consistent with the present invention relate to managing bad blocks generated while a flash memory is being used. More particularly, the present invention relates to a method for managing bad blocks in a flash memory to thereby minimize flash operations. Further, the present invention is directed to a method and an apparatus for protecting important information stored in the flash memory from unauthorized flash operations by a non-authenticated flash application, by establishing a certain area of the flash memory as a protected area and managing the protected area.
2. Description of the Related Art
A flash memory is a device for storing data therein, such as a RAM (random access memory), a ROM (read only memory) or a hard disk. The flash memory has a plurality of blocks and an erase operation is performed on a block basis.
Each block of the flash memory is limited in the number of times the data therein can be erased. Thus, if the number of times a block of the flash memory has been erased exceeds the limited number of erasures as predetermined when it was manufactured at a factory, the concerned block turns bad. In addition, as the number of erasures of a block having a bad physical property approaches the limited number of erasures, the concerned block turns bad. A flash memory such as NAND flash memory may be manufactured with some bad blocks. Taking this into consideration, the manufacturer directs users how to find the bad blocks therein. When a read operation is performed in a block of a flash memory, different data from the data previously written in the block of the flash memory may be read, and at this time, the concerned block also turns bad. These bad blocks may be generated from any of the blocks while the flash memory is in use, or they may have existed even before the flash memory is used. Existence of the bad blocks may cause troubles when using the flash memory.
To manage the bad blocks, management information for the bad blocks is needed. This management information may be stored in separate memories such as a RAM or an EEPROM. However, when the management information is stored in the RAM, the information stored in the RAM may be entirely lost if the power supply is suspended or terminated. When the management information is stored in a separate memory such as EEPROM, the cost to construct a system, therefore, increases, and the system is accordingly complicated.
To solve these problems, U.S. Pat. No. 6,260,156 discloses a method for managing bad blocks in a flash memory system, wherein a certain area in the flash memory is allotted for the management of bad blocks.
FIG. 1 is a block diagram illustrating a structure of a chunk as a basic unit for management of bad blocks. Referring to the prior art, a flash memory area is divided into a data area and a spare area, wherein the data area is used to write and erase actual data and the spare area is to manage bad blocks if generated, being classified into plural chunks. The chunk illustrated in FIG. 1 comprises (y+1) spare blocks (#0 to #y). In each chunk, an original chunk map is stored in a space whose memory address is higher and a copy chunk map is stored in each of the spare blocks. There exists a working chunk map in a RAM, a volatile memory.
FIG. 2 illustrates an enlarged spare block #0 to show a full structure of the chunk. Referring to this figure, an original chunk map and a copy chunk map in a flash memory and a working chunk map in a RAM all have the same data structure. First, meta information to manage the bad blocks, for example, the number of total blocks, the size of chunk map or the state of chunk map and the like, is stored a bad block management header (BBM header). There are (y+1) BBM entries as many as (y+1) spare blocks, and a BBM entry comprises a valid field and a bad data block number. An entry stores therein information for mapping a bad block into a spare block to replace the bad block. For example, if the bad data block number in the entry #7 is 10, this indicates that the bad block numbered 10 is remapped in the spare block #7 of the n-th chunk.
The conventional mapping is done as follows. A bad block manager is initialized through a formatting of the bad block manager, formatting a chunk and mounting of the chunk. Initialization of the bad block manager is completed when the chunk has been mounted. In the mounting of the chunk, a copy chunk map and an original chunk map of a flash memory are read and a working chunk map is generated in a RAM. At this time, both the copy chunk map and the original chunk map are maintained in the flash memory, whereby data can be recovered notwithstanding any error generated in the course of a variety of operations. When the initialization of the bad block manager is completed, the chunk is in the Ready state. To approach a specific block, it is inspected whether any block requested for each chunk exists in an entry and, if such a block exists, remapping is done. To summarize an algorithm when a new bad block is found, an available but unused entry is first found, a chunk map containing the entry is read and it is written onto the working chunk map. Then, new mapping information is written onto the unused entry from which the working chunk map is found. Subsequently, the changed remapping information is recorded in the original chunk map and the copy chunk map of the flash memory.
The conventional mapping art described above performs write and erase operations several times in a flash memory so as to maintain consistency between the copy chunk map and the original chunk map of the flash memory and the working chunk map in the RAM. For example, when a new bad block involved in an execution time is generated, the following operations are needed.
1. An erase operation to erase an original chunk map block,
2. A write operation to write an original chunk map on the original chunk map block,
3. A write operation to write a state of the original chunk map block as “Invalid,”
4. An erase operation to erase a copy chunk map block,
5. A write operation to write a copy chunk map on the copy chunk map block,
6. A write operation to write a state of the original chunk map block as “Valid.”
Two erase operations and four write operations are done in a flash memory. Further, since mapping information of bad blocks and spare blocks are stored in plural chunks, a complicated algorithm mounting each chunk should be run to manage the bad blocks and maintain consistency among chunk maps existing in the chunks. In this view, it is necessary not to increase the number of flash operations although bad blocks involved in execution time are generated.
The flash memory has generally been used as a storage device for data only, but its use has recently been extended to store data such as operating system (OS) ROM images or boot loaders which are in need of being protected. Since data such as OS ROM images or boot loaders plays an important role in a system operation, it is necessary to protect an area containing the data from erasure or write operations which may be caused due to unauthorized operation of a flash memory-related software or a user's error. In other words, a certain area of the flash memory needs to be set to a read-only area and to be managed. Even a flash memory with an established read-only area needs a method to replace bad blocks which have been generated or will be generated within the area. In this regard, the flash memory also needs to set new blocks to replace bad blocks as a read-only block and manage them.